package com.liudaolunhui.cgllibproxy;

import java.lang.reflect.Method;

import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;
import net.sf.cglib.proxy.MethodProxy;

public class CglibProxy implements MethodInterceptor {
	private Enhancer enhancer = new Enhancer();
	public Object getProxy(Class<?> Clazz){
		//设置创建子类的类
		enhancer.setSuperclass(Clazz);
		enhancer.setCallback(this);
		return enhancer.create();
	}
	
	@Override
	public Object intercept(Object obj, Method method, Object[] args,
			MethodProxy proxy) throws Throwable {
		//代理类调用父类的方法
		System.out.println("计时开始");
		proxy.invokeSuper(obj,args);
		System.out.println("计时结束");
		return null;
	}

}
